module.exports = app => {
    const { INTEGER, DATE } = app.Sequelize;
    const PostHistory = app.model.define('post_history', {
        id: {
            type: INTEGER(20),
            primaryKey: true,
            autoIncrement: true,
            comment:"自增ID"
        },
        userId: {
            type: INTEGER(20),
            allowNull: false,
            defaultValue: 0,
            comment: '用户的id'
        },
        postId: {
            type: INTEGER(20),
            allowNull: false,
            defaultValue: 0,
            comment: '帖子id'
        },
        created_time: DATE,
        updated_time: DATE,
    });
    // 关联关系
    PostHistory.associate = function () {
        // 关联用户
        PostHistory.belongsTo(app.model.User, {as:'history_user', foreignKey:'user_id', targetKey:'id'});
        // 关联帖子
        PostHistory.belongsTo(app.model.Post, {as:'history_post', foreignKey:'post_id', targetKey:'id'});
    }
    return PostHistory;
};